package com.seezoon.application.device.executor;

import com.seezoon.application.device.dto.SoundRecordingCmd;
import com.seezoon.domain.dao.po.DeviceInfoPO;
import com.seezoon.domain.service.device.DeviceService;
import com.seezoon.infrastructure.configuration.context.SecurityContextHolder;
import com.seezoon.infrastructure.dto.Response;
import com.seezoon.infrastructure.rpc.jt808.SendCommandService;
import com.seezoon.infrastructure.rpc.jt808.dto.SoundRecordingRequest;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;

/**
 * 录音命令执行器
 */
@RequiredArgsConstructor
@Slf4j
@Component
@Validated
public class SoundRecordingCmdExe {

    private final SendCommandService sendCommandService;
    private final DeviceService deviceService;

    public Response execute(@Valid @NotNull SoundRecordingCmd cmd) {
        DeviceInfoPO deviceInfoPO = deviceService.sendDeviceMsgCheck(SecurityContextHolder.getUid(), cmd.getDeviceId());
        // 构建请求对象
        SoundRecordingRequest request = new SoundRecordingRequest();
        request.setCommand(cmd.getCommand());
        request.setTime(cmd.getTime());
        request.setSaveFlag(cmd.getSaveFlag());
        request.setSampleRate(cmd.getSampleRate());
        sendCommandService.execute(deviceInfoPO.getCurrentEndpoint(),
                SendCommandService.COMMAND_SOUND_RECORDING, request, deviceInfoPO.getSimNumber());
        return Response.success();
    }
} 